package cn.wei.reallyEnjoy.home.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.wei.reallyEnjoy.R;
import cn.wei.reallyEnjoy.home.bean.DiaryBean;
import cn.wei.reallyEnjoy.utils.Constants;

public class RecommendGridVIewAdapter extends BaseAdapter {
    private final Context mContext;
    private final List<DiaryBean> datas;

    public RecommendGridVIewAdapter(Context mContext, List<DiaryBean> diaryBeanList) {
        this.mContext = mContext;
        this.datas = diaryBeanList;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView==null){
            convertView = View.inflate(mContext, R.layout.item_hot_grid_view,null);
            viewHolder = new ViewHolder();
            viewHolder.iv_img = convertView.findViewById(R.id.iv_img);
            viewHolder.tv_title = convertView.findViewById(R.id.tv_title);
            viewHolder.iv_user_headimg = convertView.findViewById(R.id.iv_user_headimg);
            viewHolder.iv_user_name = convertView.findViewById(R.id.iv_user_name);
            viewHolder.tv_favorites = convertView.findViewById(R.id.tv_favorites);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        //根基位置得到对应的数据
        DiaryBean diaryBean = datas.get(position);
        //Todo
        Glide.with(mContext).load(Constants.IMG_URL+diaryBean.getContentImg()).into(viewHolder.iv_img);
        viewHolder.tv_title.setText(diaryBean.getTitle());
        Glide.with(mContext).load(Constants.IMG_URL+diaryBean.getUheadImg()).into(viewHolder.iv_user_headimg);
        viewHolder.iv_user_name.setText(diaryBean.getUname());
        viewHolder.tv_favorites.setText(diaryBean.getPrefer());
        return convertView;
    }
    static class ViewHolder{
        ImageView iv_img;
        TextView tv_title;
        ImageView iv_user_headimg;
        TextView iv_user_name;
        TextView tv_favorites;
    }
}
